package com.atguigu.gulimall.product.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;

/**
 * Copyright (c) 2019-2029 星大陆 All Rights Reserved
 * <p>
 * Project: gulimall
 * Package: com.atguigu.gulimall.product.config
 * Version: V 1.0
 * <p>
 * Created by guoxiaolong on 2021/01/08 16:55
 */
@Configuration
public class MyRedissonConfig {

    /**
     * 所有对 Redission 的使用都是通过 RedissionCLient 对象
     *
     * @return
     * @throws IOException
     */
    @Bean(destroyMethod = "shutdown")
    public RedissonClient redisson() throws IOException {

        //1、创建配置
        // Redis url should start with redis:// or rediss://
        Config config = new Config();
        config.useSingleServer().setAddress("redis://192.168.174.102:6379");

        //2、根据 Config 创建 RedissionClient 示例
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}
